package com.yuexun.beilunpatient.ui.registration.presenter.impl;

import com.yuexun.beilunpatient.base.BaseEntity;
import com.yuexun.beilunpatient.ui.registration.bean.AppointmentPatientDetail;
import com.yuexun.beilunpatient.ui.registration.model.IRegistrationModel;
import com.yuexun.beilunpatient.ui.registration.presenter.IAppointmentRegisterPresenter;
import com.yuexun.beilunpatient.ui.registration.ui.view.IAppointmentRegisterView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/11/14.
 */
public class AppointmentRegisterPresenter implements IAppointmentRegisterPresenter {

    private IAppointmentRegisterView view;
    private IRegistrationModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public AppointmentRegisterPresenter(IRegistrationModel model, IAppointmentRegisterView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void appointmentRegister(Map<String, String> praise) {
        model.appointmentRegister(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<String>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("预约挂号会员注册失败");
                    }

                    @Override
                    public void onNext(BaseEntity<String> baseEntity) {
                        view.appointmentRegister(baseEntity);
                    }
                });
    }

    @Override
    public void loadPatientInfoDetail(Map<String, String> praise) {
        model.loadPatientInfoDetail(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<AppointmentPatientDetail>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取病人详情失败");
                    }

                    @Override
                    public void onNext(BaseEntity<AppointmentPatientDetail> baseEntity) {
                        view.loadPatientInfoDetail(baseEntity);
                    }
                });
    }
}
